﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Yosca
{
	/// <summary>
	/// Interaction logic for InvStatus.xaml
	/// </summary>
	public partial class InvStatus : Window
	{
		Database dbase = Database.Instance;
		Invoice inv;
		Label res;
		public InvStatus(Invoice profile, Label result)
		{
			this.InitializeComponent();
			// Insert code required on object creation below this point.
			inv = profile;
			res = result;
			initialize();
			
		}
		
		private void initialize()
		{
			int status = inv.invoiceStatus;
			switch(status)
			{
				case 1:	estimate.IsEnabled = false;
					    break;
				case 2: estimate.IsEnabled = false;
						jobSched.IsEnabled = false;
						break;
				case 3: estimate.IsEnabled = false;
						jobSched.IsEnabled = false;
						payDue.IsEnabled = false;
						break;
				case 4: estimate.IsEnabled = false;
						jobSched.IsEnabled = false;
						payDue.IsEnabled = false;
						payment.IsEnabled = false;
						break;
				case 5: estimate.IsEnabled = false;
						jobSched.IsEnabled = false;
						payDue.IsEnabled = false;
						payment.IsEnabled = false;
						paid.IsEnabled = false;
						break;
				default: break;
			}
		}

		private void okClick(object sender, System.Windows.RoutedEventArgs e)
		{
			if (jobSched.IsChecked == false && payDue.IsChecked == false && payment.IsChecked == false && paid.IsChecked == false)
			{
				MessageBox.Show("Please Choose One..");
				return;
			}
				
			if (MessageBox.Show("Permanently Change Invoice Status?","Confirm Change", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
			{
				if (jobSched.IsChecked == true)
				{
					inv.invoiceStatus = 2;
				//	inv.scheduledDate = DateTime.Today.Date;
				}
				else if (payDue.IsChecked == true)
					inv.invoiceStatus = 3;
				else if (payment.IsChecked == true)
					inv.invoiceStatus = 4;
				else if (paid.IsChecked == true)
					inv.invoiceStatus = 5;
				
				
				res.Content = inv.invoiceStat;
				dbase.db.Store(inv);
				dbase.db.Store(inv.defCust);
				dbase.db.Commit();	
				this.Close();
			}
			else
			{
				MessageBox.Show("Canceled");
				this.Close();
			}	
				
		}
	}
}